<template>
  <div>
    <div class="video_title">
      <van-icon name="arrow-left" class="icon" @click="goBack" />
      <p>试题搜索</p>
    </div>
    <div
      style="
        display: flex;
        align-items: center;
        width: 100%;
        padding-right: 12px;
      "
    >
      <van-search
        v-model="keyword"
        placeholder="请输入关键词"
        @search="search"
        style="flex: 1"
      />
      <van-button
        style="height: 38px; background: #327bff; color: #fff"
        @click="search"
        v-loading="loading"
        >搜索</van-button
      >
    </div>
    <p style="text-align: left; margin-left: 1rem; color: red">
      注：请从题干第一个字符开始输入查询
    </p>
    <div
      style="height: calc(100vh - 2.75rem - 60px); overflow: auto"
      v-loading="loading"
    >
      <van-empty description="内容为空" v-if="list.length == 0" />
      <div style="margin-left: 5px" v-for="(item, index) in list" :key="index">
        <span style="font-size: 1rem; display: block; padding: 1rem 0"
          >{{ item.name }}、{{ item.stem }}</span
        >
        <div
          style="
            line-height: 8.75rem;
            display: inline-block;
            height: 8.75rem;
            margin-bottom: 2.125rem;
          "
          v-if="item.stem_img"
        >
          <img :src="item.stem_img" style="height: 100%" alt="" />
        </div>
        <van-checkbox-group
          v-model="item.checkList"
          v-if="item.qtype == '多选'"
          disabled="disabled"
        >
          <div v-for="(item, index) in item.tiList" :key="index">
            <van-checkbox v-if="item.content" :name="item.cred"
              >{{ item.content }}
              <template #icon="props">
                <template v-if="props.checked">
                  <img
                    class="img-iconA"
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    :class="
                      item.daan && item.answer == item.cred
                        ? 'img-iconA'
                        : 'img-icon'
                    "
                    :src="
                      item.daan && item.answer == item.cred
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/${item.cred}.png`)
                    "
                  />
                </template>
              </template>
            </van-checkbox>
          </div>
        </van-checkbox-group>
        <van-radio-group
          v-model="item.daan"
          v-if="item.qtype == '单选'"
          disabled="disabled"
        >
          <!--  -->
          <div v-for="(item, index) in item.tiList" :key="index">
            <van-radio v-if="item.content" :name="item.cred"
              >{{ item.content }}
              <template #icon="props">
                <template v-if="props.checked">
                  <img
                    class="img-iconA"
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    :class="
                      item.daan && item.answer == item.cred
                        ? 'img-iconA'
                        : 'img-icon'
                    "
                    :src="
                      item.daan && item.answer == item.cred
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/${item.cred}.png`)
                    "
                  />
                </template>
              </template>
            </van-radio>
          </div>
        </van-radio-group>
        <van-radio-group
          v-model="item.daan"
          v-if="item.qtype == '判断'"
          disabled="disabled"
        >
          <template>
            <van-radio name="正确" class="pd">
              正确
              <template #icon="props">
                <template v-if="props.checked">
                  <img
                    class="img-iconA"
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    :class="'img-iconA'"
                    :src="
                      item.daan && item.answer == '正确'
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/PD.png`)
                    "
                  />
                </template>
              </template>
            </van-radio>
            <van-radio name="错误" class="pd">
              错误
              <template #icon="props">
                <template v-if="props && props.checked">
                  <img
                    class="img-iconA"
                    :src="
                      errORpass
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/error.png`)
                    "
                  />
                </template>
                <template v-else>
                  <img
                    :class="'img-iconA'"
                    :src="
                      item.daan && item.answer == '错误'
                        ? require(`@/assets/mobile/exam/pass.png`)
                        : require(`@/assets/mobile/exam/PD.png`)
                    "
                  />
                </template>
              </template>
            </van-radio>
          </template>
        </van-radio-group>
      </div>
    </div>
  </div>
</template>

<script>
import { questionsearch } from "@/api/admin.js";
import { getsubject_id } from "@/utils/auth";
export default {
  data() {
    return {
      keyword: "",
      list: [],
      errORpass: true,
      loading: false,
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    search() {
      this.list = [];
      if (this.keyword == "") return this.$message.error("关键词不能为空");
      this.loading = true;
      // this.list = [];
      questionsearch({
        keyword: this.keyword,
        subjectid: getsubject_id(),
      }).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          res.data.list.map((item, index) => {
            item.tixu = index + 1;
            this.list.push(this.funChangeTi(item));
          });
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    funChangeTi(item) {
      let Arr = [];
      Arr.push(
        {
          cred: "A",
          content: item.a,
          content_img: item.a_img,
        },
        {
          cred: "B",
          content: item.b,
          content_img: item.b_img,
        },
        {
          cred: "C",
          content: item.c,
          content_img: item.c_img,
        },
        {
          cred: "D",
          content: item.d,
          content_img: item.d_img,
        },
        {
          cred: "E",
          content: item.e,
          content_img: item.e_img,
        },
        {
          cred: "F",
          content: item.f,
          content_img: item.f_img,
        }
      );
      return {
        name: item.tixu,
        stem: item.stem,
        tiList: Arr,
        answer: item.answer,
        daan: item.answer,
        checkList: item.answer.split(""),
        analysis: item.analysis,
        id: item.id,
        qtype: item.qtype,
        stem_img: item.stem_img,
      };
    },
  },
};
</script>

<style lang="scss" scoped>
.video_title {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #327bff;
  color: #fff;
  height: 2.75rem;

  p {
    margin: 0;
    width: calc(100vw - 64px);
    display: flex;
    justify-content: center;
  }
  .icon {
    font-size: 1.25rem;
  }
}
.img-icon {
  height: 2rem;
  width: 2rem;
}
.img-iconA {
  height: 1.2rem;
  width: 1.2rem;
  margin: 0 0.2rem;
}
::v-deep {
  .van-checkbox {
    min-height: 3.2rem;
  }
  .van-radio {
    min-height: 2rem;
  }
  .pd {
    display: flex;
    align-items: center;
    .van-radio__icon {
      display: flex;
      align-items: center;
    }
  }
  .van-radio__icon {
    min-height: 2rem;
  }
  .van-radio__label {
    font-size: 1rem;
  }
  .van-checkbox__icon {
    min-height: 2rem;
  }
  .van-checkbox__label {
    font-size: 1rem;
  }
  .van-radio__label--disabled {
    color: #323233;
  }
  .van-checkbox__label--disabled {
    color: #323233;
  }
  .van-cell {
    line-height: 30px;
    .van-field__control {
      font-size: 1.2rem;
    }
  }
  .van-search__action {
    line-height: 30px;
    font-size: 1.2rem;
    background: dodgerblue;
    padding-top: 5px;
    padding-bottom: 5px;
    margin-right: 12px;
    color: #fff;
  }
  .van-icon-search:before {
    font-size: 1.1rem;
  }
}
</style>
